package com.caldera.vaquita;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.Spinner;

public class VaquitaConf extends Activity{
	VaquitaUtils utils;
	VaquitaData data;
	SQLiteDatabase db;
	Cursor rs;
	String sql;
	
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.config);
        
        data=new VaquitaData(this);
        db=data.getReadableDatabase();
        sql="select _id, nombre, pmes, pdia, simbolo from conf;";
        rs=db.rawQuery(sql, null);
        if(rs.moveToNext()){
        	((EditText)findViewById(R.id.confFmNombre)).setText(rs.getString(1));
        	((EditText)findViewById(R.id.confFmPMes)).setText(rs.getString(2));
        	((EditText)findViewById(R.id.confFmPDia)).setText(rs.getString(3));
        	((EditText)findViewById(R.id.confFmSimbolo)).setText(rs.getString(4));
        }
    }
    public void onUpdate(View v){
    	utils=new VaquitaUtils(this);
    	String nombre=((EditText)findViewById(R.id.confFmNombre)).getText().toString();
    	double pmes=Double.parseDouble( ((EditText)findViewById(R.id.confFmPMes)).getText().toString() );
    	double pdia=Double.parseDouble( ((EditText)findViewById(R.id.confFmPDia)).getText().toString() );
    	String simbolo=((EditText)findViewById(R.id.confFmSimbolo)).getText().toString();
    	
        data=new VaquitaData(this);
        db=data.getWritableDatabase();
        sql="update conf set nombre='"+nombre+"', pmes="+pmes+", pdia="+pdia+", simbolo='"+simbolo+"' where _id="+1+";";
        db.execSQL(sql);
    	
		startActivity(new Intent(this, VaquitaActivity.class));
    }
}
